import os, time
from selenium import webdriver

chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"  # 浏览器驱动位置
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
file_path = 'file:///' + os.path.abspath('frame.html')
driver.get(file_path)
# 默认取ID或name
driver.switch_to.frame("if")
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
time.sleep(3)
# 回到上一层
driver.switch_to.parent_frame()
# 回到顶层
driver.switch_to.default_content()
driver.quit()
